﻿myApp.controller('TenancyCalculatorController', function ($scope, $http, ngTableParams, $filter, $templateCache) {
    $scope.$emit('newPageLoaded', {
        'title': 'Tenancy Agreement Calculator | ShiJie Property',
        'description': 'Tenancy Agreement Calculator. Estimate Your Tenancy Agreement Fee Using This Simple To Use Calculator. Go Now!',
        'keywords': 'tenancy agreement calculator, tenancy agreement, tenancy calculator'
    });

    //$scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 Tenancy Calculator', 'description': 'Free online tenancy calculator. Try it now.' });


    $scope.isCalculated = false;
   
    $scope.isEmpty = function (obj) {
        for (var i in obj) if (obj.hasOwnProperty(i)) return false;
        return true;
    };

    $scope.calculate = function () {
        // http://expatriateadvisory.com/guide-in-renting-a-property-in-malaysia/

       
        var rentalTotal = $scope.rentalPrice * 12;
        if ($scope.addionalCopy == null) {
            $scope.addionalCopy = 0;
        }
        $scope.stampDuty = (rentalTotal - 2400) / 250 * stampDutyRate($scope.tenancyPeriod);

        if ($scope.tenancyPeriod < 4) {
            if ($scope.rentalPrice < 10000)
                $scope.tenancyCharges = $scope.rentalPrice * 0.25;
            else
                $scope.tenancyCharges = 10000 * 0.25 + ($scope.rentalPrice - 10000) * 0.20;
        }
        else {
            if ($scope.rentalPrice < 10000)
                $scope.tenancyCharges = $scope.rentalPrice * 0.50;
            else
                $scope.tenancyCharges = 10000 * 0.50 + ($scope.rentalPrice - 10000) * 0.20;

        }
        $scope.total_copy = $scope.addionalCopy * 10;
        $scope.total = $scope.tenancyCharges + $scope.stampDuty + ($scope.addionalCopy * 10)
        $scope.isCalculated = true;
    }
    function stampDutyRate(year) {
        if (year < 2)
            return 1;
        else if (year <= 3)
            return 2;
        else
            return 3;

    }


});